export default {
	install(Vue) { // 使用install的形式进行安装mixin
		Vue.mixin({
			data() {
				return {
					userRules: {
						
						loginPhone: {
							rules: [
								{
									required: true,
									'errorMessage': "手机号不能为空"
								},
								{
									validateFunction: this.validatePhone
								} // 自定义验证规则
							]
						},
						loginPassword: {
							rules: [{
									required: true,
									'errorMessage': "密码不能为空"
								},
								{
									validateFunction: this.validatePwd
								}
							]
						},
						messageCode: {
							rules: [
								// { required: true, 'errorMessage': "密码不能为空" },
							]
						},
						registerPhone: {
							rules: [{
									required: true,
									'errorMessage': "手机号不能为空"
								},
								{
									validateFunction: this.validatePhone
								} // 自定义验证规则
							]
						},
						registerPassword: {
							rules: [
								{
									required: true,
									'errorMessage': "密码不能为空"
								},
								{
									validateFunction: this.validatePwd
								} // 自定义验证规则
							]
						},
						againRegisterPassword: {
							rules: [{
									required: true,
									'errorMessage': "密码不能为空"
								},
								{
									validateFunction: this.validateAgainPwd
								} // 自定义验证规则
							]
						},
					},
					mobileReg: /^1[3,4,5,6,7,8,9][0-9]{9}$/,
					restoreRules: {
						payIndex: {
							rules: [{
								required: true,
								'errorMessage': "输入不能为空",

							}]
						},
						ordervalue: {
							rules: [{
								minLength: 3,
								required: true,
								'errorMessage': "输入不能为空"
							}]
						},
						phone: {
							rules: [{
									required: true,
									'errorMessage': "手机号不能为空"
								},
								{
									validateFunction: this.validatePhone
								} // 自定义验证规则
							]
						},
						pwd: {
							rules: [{
									required: true,
									'errorMessage': "密码不能为空"
								},
								{
									validateFunction: this.validatePwd
								} // 自定义验证规则
							]
						},
						againPwd: {
							rules: [{
									required: true,
									'errorMessage': "密码不能为空"
								},
								{
									validateFunction: this.validateRestoreAgainPwd
								} // 自定义验证规则
							]
						}
					}
				}
			},

			methods: {
				/* 验证手机号码 */
				validatePhone(rule, val, data, callback) {

					switch (true) {
						case !this.mobileReg.test(val):
							callback('手机号码格式不正确')
							break;
						default:
							return true
					}
				},
				//验证密码长度（不能少于6位）
				validatePwd(rule, val, data, callback) {
					switch (true) {
						case val.length < 6:
							callback('密码长度不能少于6位')
							break;
						default:
							return true
					}
				},
				validateAgainPwd(rule, val, data, callback) {
					switch (true) {
						case val != this.formRegisterData.registerPassword:
							callback('两次密码不一致')
							break;
						default:
							return true
					}
				},
				validateAgainNewPwd(rule, val, data, callback) {

					switch (true) {
						case val != this.editUser.newPwd:
							callback('两次密码不一致')
							break;
						default:
							return true
					}
				},
				validateChannel(rule, val, data, callback) {
					console.log(this, val)
					switch (true) {
						case val.length > 0:
							callback('不能为空')
							break;
						default:
							return true
					}
				},
				validateRestoreAgainPwd(rule, val, data, callback) {
					console.log(data)
					switch (true) {
						case val != this.formRestoreData.pwd:
							callback('两次密码不一致')
							break;
						default:
							return true
					}
				}
			}
		})
	}
}